﻿

using HBase;
using hcollection;
using System.Collections.Generic;

namespace hCommand {
    public abstract class AbsClearCarrierTask :ZtTask {
        public AbsClearCarrierTask() {
            time = 3000;
        }
        protected IWCSServer wcsServer = WMSDalFactray.getDal<IWCSServer>();


        protected abstract Signal getCarrierSignalStatus(int path);
        protected abstract void ClearTask(PlcCarrierPoint point);
        public override bool excute() {

            List<PlcCarrierPoint> carrierPoint = MyCache.getList<PlcCarrierPoint>();
            foreach( var it in carrierPoint ) {
                if( it.p == 0 ) {
                    continue;
                }
                Signal carrierSignal = getCarrierSignalStatus(it.p);
                if( it.p == 6 ) {
                    it.p = 6;
                }
                if( carrierSignal == null ) {
                    continue;
                }
                int taskNO = carrierSignal.no;
                if( taskNO == 0 ) {
                    continue;
                }
                if( !carrierSignal.isArrived() ) {
                    continue;
                }
                TaskCarrier taskCarrier = PathFacade.getTaskByTaskNo<TaskCarrier>(taskNO);

                if( taskCarrier == null ) {
                    ClearTask(it);
                    fileAll("托盘号为 " + taskNO + "的出入库任务不存在！ ");
                    continue;
                }
                int path = it.p;
                if( taskCarrier.des != path ) {
                    continue;
                }
                if( taskCarrier.status != 9 ) {
                    continue;
                }
                TaskCrane taskCrane = PathFacade.getNextTaskByTaskNo<TaskCarrier ,TaskCrane>(path ,taskCarrier.taskNo);
                if( taskCrane != null ) {
                    if( taskCrane.status > 4 ) {
                        ClearTask(it);
                    }
                } else {
                    ClearTask(it);
                }
            }
            return true;
        }


    }
}
